package org.oos.services.util;

import java.text.SimpleDateFormat;

import org.jdom.Element;
import org.jdom.Namespace;
import org.oos.data.Area;

public class DomUtils
{
	Namespace ns_oos;
	Namespace ns_georss;
	Namespace ns_default;
	Namespace ns_app;
	public final SimpleDateFormat RFC3339 = new SimpleDateFormat("yyyy-MM-dd'T'h:m:ss.SZ");
	public final String ENTRY = "entry";
	public final String ID = "id";
	
	static DomUtils myself;
	
	public DomUtils()
	{
		ns_oos = Namespace.getNamespace("oos", "http://11870.com/api/oos");
		ns_georss = Namespace.getNamespace("georss", "http://www.georss.org/georss/10");
		ns_default = Namespace.getNamespace("http://www.w3.org/2005/Atom");
		ns_app = Namespace.getNamespace("app", "http://www.w3.org/2007/app");
	}
	
	
	public static DomUtils getInstance()
	{
		if (myself == null)
			myself =new DomUtils();
		return myself;
	}

	public Element makeOosElement(String name, String value)
	{
		Element element = new Element(name, ns_oos);
		element.setText(value);
		return element;
	}

	public Element makeAreaElement(String name, Area area)
	{
		Element element = new Element(name, ns_oos);
		element.setText(area.name);
		element.setAttribute("slug", area.url);
		return element;
	}
}
